package Dao;

import Pojo.Site;
import Utils.DBUtil;
import org.apache.log4j.Logger;

import java.sql.SQLException;
import java.util.Arrays;

public class SiteDao {
    private final DBUtil dbUtil = new DBUtil();
    private final Logger logger = Logger.getLogger(SiteDao.class);

    /**
     * 获取站点信息
     *
     * @return
     * @throws SQLException
     */
    public Site getSiteAll() throws SQLException {
        String sql = "select siteTitle,siteSubTitle,siteContent,siteKeyword from `site`";
        return dbUtil.queryData(sql, null, Site.class);
    }

    public int updateSiteIsAdmin(Site site) throws SQLException {
        String sql = "update `site` set " +
                "siteTitle = ? ," +
                "siteSubTitle = ? ," +
                "siteContent = ? ," +
                "siteKeyword = ? " +
                "where siteId = 0";
        Object[] params = {site.getSiteTitle(), site.getSiteSubTitle(), site.getSiteContent(), site.getSiteKeyword()};
        logger.info("sql=>" + sql);
        logger.info("params=>" + Arrays.toString(params));
        return dbUtil.update(sql, params);
    }
}
